//
//  VMCActivityIndicator.m
//  app
//
//  Created by bigknife on 14/11/12.
//  Copyright (c) 2014年 zzt. All rights reserved.
//

#import "VMCActivityIndicator.h"

@interface VMCActivityIndicator()
@property (nonatomic,strong) UIImageView *imgIndicator;
@end

@implementation VMCActivityIndicator

-(void)willMoveToSuperview:(UIView *)newSuperview{
    
}
-(void)layoutSubviews{
    [super layoutSubviews];
    if(!self.imgIndicator.image){
        self.imgIndicator.image = [UIImage imageNamed:self.indicatorImageName];
    }
    self.imgIndicator.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame));
}
-(UIImageView *)imgIndicator{
    if (!_imgIndicator) {
        _imgIndicator = [UIImageView new];
        [self addSubview:_imgIndicator];
    }
    return _imgIndicator;
}

-(void)startAnimating{
    CALayer *layer = self.imgIndicator.layer;
    CABasicAnimation *rotation;
    rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    rotation.fromValue = [NSNumber numberWithFloat:0];
    rotation.toValue = [NSNumber numberWithFloat:(2 * M_PI)];
    rotation.duration = 0.7f; // Speed
    rotation.repeatCount = HUGE_VALF; // Repeat forever. Can be a finite number.
    [layer removeAllAnimations];
    [layer addAnimation:rotation forKey:@"Spin"];
}
-(void)stopAnimating{
    [self.imgIndicator.layer removeAllAnimations];
}

@end
